package org.bbelovic.devel.exercises;

import java.util.ArrayList;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import java.util.List;

public class FootballKataLineProcessor implements LineProcessor {

    private static final String LINE_DELIMITER_1 = "-";
    private static final String LINE_DELIMITER_2 = "\\s+";
    private static final int TOKEN_COUNT_AFTER_FIRST_SPLIT = 2;
    private static final int TOKEN_COUNT_AFTER_SECOND_SPLIT = 9;

    public List<String> processLine(final String inputLine) {
        if (inputLine == null) {
            return emptyList();
        }
        final String [] tokens = inputLine.trim().split(LINE_DELIMITER_1);
        if (tokens.length != TOKEN_COUNT_AFTER_FIRST_SPLIT) {
            return emptyList();
        }
        final List<String> first = asList(tokens[0].trim().split(LINE_DELIMITER_2));
        final List<String> second = asList(tokens[1].trim().split(LINE_DELIMITER_2));
        final List<String> result = new ArrayList<>(first);
        result.addAll(second);
        if (result.size() != TOKEN_COUNT_AFTER_SECOND_SPLIT) {
            return emptyList();
        }
        return result;
    }

}
